package com.schematic.android.utils
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.ui.Multitouch;
import flash.events.TransformGestureEvent;
import flash.events.MouseEvent;

/**
 * This class provides a basic starting point to test a device's 
 * multi touch capabilities
 */
public class TouchCapabilitiesMonitor extends Sprite
{

    //--------------------------------------------------------------------------
    //
    // Constructor
    //
    //--------------------------------------------------------------------------

    /**
     * Creates a new instance of this class.
     */    
    public function TouchCapabilitiesMonitor()
    {
        super();
        
        gestures = new TextField();
        gestures.autoSize = TextFieldAutoSize.LEFT;
        gestures.y = 490;
        gestures.text = "gesture monitor";
        addChild(gestures);
        
        capabilities = new TextField();
        capabilities.y = 510;
        capabilities.multiline = true;
        capabilities.autoSize = TextFieldAutoSize.LEFT;
        addChild(capabilities);        
        
        capabilities.appendText("Multitouch.inputMode:");
        capabilities.appendText("\n");
        capabilities.appendText(Multitouch.inputMode);
        capabilities.appendText("\n");
        capabilities.appendText("\n");
        capabilities.appendText("Multitouch.maxTouchPoints:");
        capabilities.appendText("\n");
        capabilities.appendText(Multitouch.maxTouchPoints.toString());
        capabilities.appendText("\n");
        capabilities.appendText("\n");
        capabilities.appendText("Multitouch.supportedGestures:");
        capabilities.appendText("\n");
        capabilities.appendText(Multitouch.supportedGestures.join(" - "));
        capabilities.appendText("\n");
        capabilities.appendText("\n");
        capabilities.appendText("Multitouch.supportsGestureEvents:");
        capabilities.appendText("\n");
        capabilities.appendText(Multitouch.supportsGestureEvents.toString());
        capabilities.appendText("\n");
        capabilities.appendText("\n");
        capabilities.appendText("Multitouch.supportsTouchEvents:");
        capabilities.appendText("\n");
        capabilities.appendText(Multitouch.supportsTouchEvents.toString());
        
        touchArea = new Sprite();
        touchArea.graphics.beginFill(0x00FF00);
        touchArea.graphics.drawRect(0, 0, 480, 480);
        touchArea.graphics.endFill();
        addChild(touchArea);
        
        touchArea.addEventListener(TransformGestureEvent.GESTURE_PAN, 
            touchArea_transformGestureHandler); 
        touchArea.addEventListener(TransformGestureEvent.GESTURE_ROTATE, 
            touchArea_transformGestureHandler); 
        touchArea.addEventListener(TransformGestureEvent.GESTURE_SWIPE, 
            touchArea_transformGestureHandler); 
        touchArea.addEventListener(TransformGestureEvent.GESTURE_ZOOM, 
            touchArea_transformGestureHandler); 
        touchArea.addEventListener(MouseEvent.CLICK, touchArea_clickHandler);
        
    }

    //--------------------------------------------------------------------------
    //
    //  Variables
    //
    //--------------------------------------------------------------------------
    
    /**
     *  @private
     */
    private var capabilities:TextField;

    /**
     *  @private
     */
    private var gestures:TextField;
    
    /**
     *  @private
     */
    private var touchArea:Sprite;
    
    //--------------------------------------------------------------------------
    //
    //  Event Handlers
    //
    //--------------------------------------------------------------------------

    //----------------------------------
    //  transformGestureHandler
    //----------------------------------
    /**
     * @private
     */
    private function touchArea_transformGestureHandler(event:TransformGestureEvent):void
    {
        gestures.text = event.type;
    }

    //----------------------------------
    //  touchArea_clickHandler
    //----------------------------------
    /**
     * @private
     */
    private function touchArea_clickHandler(event:MouseEvent):void
    {
        gestures.text = event.type;
    }

}
}